package com.example.designPattern.Prototype;

import java.io.*;


public class Address implements Cloneable,Serializable {
      private  int id;
      private String PName;
      private String CName;
      private String time;

      public int getId() {
            return id;
      }

      public void setId(int id) {
            this.id = id;
      }

      public String getPName() {
            return PName;
      }

      public void setPName(String PName) {
            this.PName = PName;
      }

      public String getCName() {
            return CName;
      }

      public void setCName(String CName) {
            this.CName = CName;
      }

      public String getTime() {
            return time;
      }

      public void setTime(String time) {
            this.time = time;
      }

      public Address(int id, String PName, String CName, String time) {
            this.id = id;
            this.PName = PName;
            this.CName = CName;
            this.time = time;
      }

      public Address deepClone() throws IOException, ClassNotFoundException, OptionalDataException {

            //将对象写入流中

            ByteArrayOutputStream bao=new  ByteArrayOutputStream();

            ObjectOutputStream oos=new  ObjectOutputStream(bao);

            oos.writeObject(this);

            //将对象从流中取出

            ByteArrayInputStream bis=new  ByteArrayInputStream(bao.toByteArray());

            ObjectInputStream ois=new  ObjectInputStream(bis);

            return  (Address)ois.readObject();
      }
}
